<?php

    namespace yaliSDK\user;

    use yaliSDK\common\BaseService;
    use yaliSDK\common\Constrants;
    use yaliSDK\common\Result;

    class UserService extends BaseService {
        private $userRpo;
        public function __construct() {
            $this->userRpo = new UserRepository();
        }
        // 检查用户是否存在
        function validUserIsExist($type) {
            if (!empty($openid)) {
                return false;
            }
            return true;
        }
        // 网红详情
        function userDetail($id = null, $options = []) {
            if (empty($id)) {
                return new Result('id', Constrants::$CUSTOMER_PARAMS_ERROR);
            }
            $user = $this->userRpo->get($id, $options);

            if (empty($user)) {
                return new Result(null, Constrants::$NO_EXIST);
            }
            return new Result($user);
        }
        // 检查角色
        function getUserRoleType($type) {
            // 检查网红数据
            switch ($type) {
                case Constrants::$ROLE_USER:
                    {
                        return ['type' => $type, 'name' => '用户'];
                        break;
                    }
                case Constrants::$ROLE_ANCHOR:
                    {
                        return ['type' => $type, 'name' => '网红'];
                        break;
                    }
                case Constrants::$ROLE_SHOPER:
                    {// 检查商家数据
                        return ['type' => $type, 'name' => '商家'];
                        break;
                    }
                default:
                    {
                        return ['type' => $type, 'name' => '无'];
                        break;
                    }

            }

        }
    }